package shingling;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xmlParser.xmlReader;
import net.sf.javaml.clustering.DensityBasedSpatialClustering;
import net.sf.javaml.clustering.mcl.MarkovClustering;
import net.sf.javaml.clustering.mcl.SparseMatrix;
public class main {
	
	public static void main(String args[])throws Exception{
		
		
		shingling abc=new shingling();
		
		ArrayList<String> titles=new ArrayList<String>();
		/*titles.add("car parked in front of the India door in");
		titles.add("scooter parked in front of the India dhome");
		
		String text[]={"car parked in front of the India door in",
						"scooter parked in front of the India dhome"
						};
		
		*/
		
		
		
		/*
		Document doc=xmlReader.createDocUrl("http://ddqrs.img.search.vip.sp2.yahoo.com:4080/?template=XMLImage&hq=on&hits=100&thumbsize=200%2C500%2C1024&l=en&stype=filter&filtertype=premium&custid=imagesearch&query=mountains&source=getty");
		doc.getDocumentElement().normalize();
		
		NodeList nList = doc.getElementsByTagName("Result");	
		for (int temp = 0; temp < nList.getLength(); temp++) {

			Node nNode = nList.item(temp);
			Element e=(Element)nNode;
			titles.add(e.getElementsByTagName("Title").item(0).getFirstChild().getNodeValue());
		}

		ArrayList<HashMap<Integer,String>> hashes=new ArrayList<HashMap<Integer,String>>();
		 for(String row:titles){
			List<List<String>> shinglesSet1= abc.shingles(row, 2,false);		
			HashMap<Integer,String> h1=abc.hashList(shinglesSet1);
			hashes.add(h1);			
		}
		 
		 
		 List<List<Double>> sim=shingling.minHash(hashes,500);
		 double[][] simMatrix=new double[100][100];
		
		 int row=0;
		 for(List<Double> temp:sim){
			 int col=0;
			 for(double val:temp){ 
				 simMatrix[row][col]=val;
				 col++;
			 }
			 row++;
		 }
		 
		 for(int i=0;i<100;i++){
			 for(int j=0;j<100;j++){
				 System.out.print(simMatrix[i][j]);
			 }
			 System.out.println();
		 }
		 
		 
		 ObjectOutputStream outputstream= new ObjectOutputStream(new FileOutputStream("out"));
		 outputstream.writeObject(simMatrix);
		 
		 
		 FileInputStream fin = new FileInputStream("out");
		 ObjectInputStream ois = new ObjectInputStream(fin);
		 double[][] simMatrix1=(double[][])ois.readObject();
		 for(int i=0;i<100;i++){
			 for(int j=0;j<100;j++){
				 System.out.print(simMatrix1[i][j]);
			 }
			 System.out.println();
		 }

		 */
		
		 
		 FileInputStream fin = new FileInputStream("out");
		 ObjectInputStream ois = new ObjectInputStream(fin);
		 double[][] simMatrix1=(double[][])ois.readObject();
		 
		 MarkovClustering cluster=new MarkovClustering();
			
		 
			double[][] matrix={{1,0.9,0.9,0.1,0.2},{0.9,1,0.9,0.1,0.2},{0.9,0.9,1,0.1,0.2},{0.1,0.1,0.1,1,0.9},{0.2,0.2,0.2,0.9,1}};
				
			SparseMatrix matrix1=new SparseMatrix(simMatrix1);
			SparseMatrix m2=cluster.run(matrix1,0.001, 2, 0,0.001);
			System.out.println(m2);
		 
		  
		 	 
	} 
	
	
	
}
